<?php
/*
	Aurus CMS - free OOP CMS
	Copyright (C) 2010  Nestor Yanchuk

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
include(ROOT.'/engine/configs/config.db.php');
$res = mysql_connect(DB_HOST,DB_LOGIN,DB_PASS);

if ( function_exists('mysql_set_charset') ) {
	mysql_set_charset('utf8', $res);
} else {
	$this->query("SET NAMES utf8",$res);
}
mysql_select_db(DB_DB,$res);
$prefix = PREFIX;


$sql[] = "CREATE TABLE IF NOT EXISTS `".PREFIX."_modules` (
  `type` varchar(15) NOT NULL,
  `name` varchar(100) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;";


$sql[] = "INSERT INTO `".PREFIX."_modules` (`type`, `name`) VALUES
('module', 'users'),
('module', 'captcha');";

$sql[] = "CREATE TABLE IF NOT EXISTS `".PREFIX."_usergroups` (
  `gid` int(11) NOT NULL auto_increment,
  `groupallow` mediumtext NOT NULL,
  PRIMARY KEY  (`gid`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";

$sql[] = <<<SQL
INSERT INTO `{$prefix}_usergroups` (`gid`, `groupallow`) VALUES
(1, 'a:13:{s:9:"groupname";s:26:"Адміністратор";s:10:"adminVisit";s:1:"1";s:9:"siteVisit";s:1:"1";s:7:"addNews";s:1:"1";s:8:"editNews";s:1:"1";s:10:"deleteNews";s:1:"1";s:17:"addCommentsToNews";s:1:"1";s:14:"addCommCaptcha";s:1:"0";s:12:"commEditSelf";s:1:"1";s:11:"commEditAll";s:1:"1";s:14:"commDeleteSelf";s:1:"1";s:13:"commDeleteAll";s:1:"1";s:13:"commPostLinks";s:1:"1";}'),
(2, 'a:13:{s:9:"groupname";s:18:"Модератор";s:10:"adminVisit";s:1:"0";s:9:"siteVisit";s:1:"1";s:7:"addNews";s:1:"1";s:8:"editNews";s:1:"0";s:10:"deleteNews";s:1:"0";s:17:"addCommentsToNews";s:1:"1";s:14:"addCommCaptcha";s:1:"0";s:12:"commEditSelf";s:1:"1";s:11:"commEditAll";s:1:"0";s:14:"commDeleteSelf";s:1:"1";s:13:"commDeleteAll";s:1:"0";s:13:"commPostLinks";s:1:"0";}'),
(3, 'a:13:{s:9:"groupname";s:20:"Користувач";s:10:"adminVisit";s:1:"0";s:9:"siteVisit";s:1:"1";s:7:"addNews";s:1:"1";s:8:"editNews";s:1:"0";s:10:"deleteNews";s:1:"0";s:17:"addCommentsToNews";s:1:"1";s:14:"addCommCaptcha";s:1:"0";s:12:"commEditSelf";s:1:"1";s:11:"commEditAll";s:1:"0";s:14:"commDeleteSelf";s:1:"1";s:13:"commDeleteAll";s:1:"0";s:13:"commPostLinks";s:1:"0";}'),
(4, 'a:13:{s:9:"groupname";s:10:"Гість";s:10:"adminVisit";s:1:"0";s:9:"siteVisit";s:1:"1";s:7:"addNews";s:1:"0";s:8:"editNews";s:1:"0";s:10:"deleteNews";s:1:"0";s:17:"addCommentsToNews";s:1:"1";s:14:"addCommCaptcha";s:1:"1";s:12:"commEditSelf";s:1:"0";s:11:"commEditAll";s:1:"0";s:14:"commDeleteSelf";s:1:"0";s:13:"commDeleteAll";s:1:"0";s:13:"commPostLinks";s:1:"0";}');
SQL;

$sql[] = "CREATE TABLE IF NOT EXISTS `".PREFIX."_users` (
  `uid` int(11) NOT NULL auto_increment,
  `login` varchar(200) NOT NULL,
  `password` varchar(100) NOT NULL,
  `email` varchar(255) NOT NULL,
  `icq` varchar(15) NOT NULL,
  `group` int(11) NOT NULL,
  `reg_date` int(11) NOT NULL,
  `country` varchar(200) NOT NULL,
  `signature` mediumtext NOT NULL,
  `about` mediumtext NOT NULL,
  `pm_count` int(11) NOT NULL,
  `unr_pm_count` int(11) NOT NULL,
  `news_count` int(11) NOT NULL,
  `com_count` int(11) NOT NULL,
  `topic_count` int(11) NOT NULL,
  `avatar` varchar(255) NOT NULL,
  `last_login` int(11) NOT NULL,
  `custom_data` mediumtext NOT NULL,
  PRIMARY KEY  (`uid`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";

foreach ($sql as $s){
	mysql_query($s,$res);
}

echo HEADER.'<h2>'.__('Таблиці створено').'</h2><a href="'.LINK_ROOT.'install/index.php?step=7">'.__('Далі').'</a>'.FOOTER;
